<?php

namespace App\Http\Requests\Admin\Settings;

use App\Http\Requests\BaseFormRequest;

class ApprovalFlowSaveFormRequest extends BaseFormRequest
{
    protected function passedValidation()
    {
        $nodes = json_decode($this->get('nodes', '{}'), true);
        $_nodes = [];
        foreach ($nodes as $k => $node) {
            $node['node_index'] = $k + 1;
            $_nodes[$k + 1] = $node;
        }
        $this->offsetSet('nodes', $_nodes);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $roles = [
            'document_type' => [
                'required'
            ],
            'role_id' => [
                'required'
            ],
            'nodes' => [
                'required'
            ],
        ];
        return $roles;
    }

    public function messages()
    {
        return [
            'document_type.required' => '单据类型',
            'role_id.required' => '角色ID',
            'nodes.required' => '审批节点'
        ];
    }
}
